<template>
  <ContentSet :title="title">
    <!-- 查询区域 -->
    <el-form :model="queryParams" :ref="queryFormRef" inline v-show="showSearch" label-width="70px" @keyup.enter.native="handleQuery">
        <el-form-item label="角色名称" prop="keywords" style="width: 270px;" >
          <el-input v-model="queryParams.keywords" placeholder="请输入关键字" clearable style="width: 180px;"/>
        </el-form-item>
        <el-form-item label-width="0px">
          <el-button type="primary" icon="el-icon-search"  @click="handleQuery" :loading="sumitLoadling">搜索</el-button>
        </el-form-item>
    </el-form>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="tool-bar-btn">
      <el-button type="primary" icon="el-icon-plus"  :disabled="multiple" v-if="useAdd" @click="handleAdd" :loading="sumitLoadling">{{addText}}</el-button>
      <el-button type="danger" icon="el-icon-delete"  :disabled="multiple" v-if="useRemove" @click="handleRemove" :loading="sumitLoadling">{{removeText}}</el-button>
    </div>

    <selected-info :count="selectedRows.length" :onClearSelected="onClearSelected" />
    <el-table :ref="dataTableRef" v-loading="loading" :data="dataList" stripe border @selection-change="onSelectChange"
          highlight-current-row :row-key="rowKey">
      <el-table-column type="selection" width="55" align="center" fixed="left"/>
      <el-table-column label="角色名称" align="center" prop="roleName"  width="150" />
      <el-table-column label="角色编码" align="center" prop="roleCode"  width="150" />
      <el-table-column label="描述" align="center" prop="description" :show-overflow-tooltip="true" />
    </el-table>

    <pagination v-show="!loading" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" layout="total, sizes, prev, pager, next"/>
  </ContentSet>
</template>

<script>
import { IndexListMixin } from '@/components/mixins/IndexListMixin';

export default {
  name: "BaseRoleList",
  mixins:[IndexListMixin],
  components: {
  },
  props: {
    title:{
      type: String,
      default: '角色列表'
    },
    sumitLoadling:{
      type: Boolean,
      default: false
    },
    userId:{
      type: String,
      require: true
    },
    selectType:{
      type: String,
      require: true
    },
    useAdd: {
      type: Boolean,
      default: false
    },
    useRemove: {
      type: Boolean,
      default: false
    },
    addText:{
      type: String,
      default: '添加'
    },
    removeText:{
      type: String,
      default: '移除'
    }
  },
  data() {
    return {
      // 查询参数
      queryParams: {
        keywords: null,
        pageNum: 1,
        pageSize: 10
      },
      url: {
      	list: '/sys/role/toSelectList'
      },
    };
  },
  created() {
    this.queryParams.selectType = this.selectType;
  },
  mounted(){
  },
  methods: {
    getList() {
      this.queryParams.userId = this.userId;
      this.loadData(this.url.list);
    },

    /** 添加按钮操作 */
    handleAdd() {
      if(this.useAdd){
        this.$emit("add", this.selectedRows)
      }
    },

    /** 移除按钮操作 */
    handleRemove() {
      if(this.useRemove){
        this.$emit("remove", this.selectedRows)
      }
    },

  }
};
</script>

<style scoped>

</style>
